package com.machinsight.library.action;

import com.machinsight.library.bean.User;
import com.machinsight.library.content.ContentValue;
import com.opensymphony.xwork2.ActionSupport;
import org.apache.struts2.ServletActionContext;

import javax.servlet.http.HttpServletRequest;

/**
 * Copyright ©2017-2019 Machinsight Technology Co., Ltd.All rights reserved.
 * Author: Zhoushaohua
 * Date: 2019/12/27
 * Description:登录action
 */
public class LoginAction extends ActionSupport {
    private final static String ROOT_NAME = "root";
    private final static String ROOT_PWD = "123456";
    private User user;

    public String doLogin() {
        //获取HttpServletRequest对象
        HttpServletRequest request = ServletActionContext.getRequest();
        //这里的key值"username"、"password"与表单中的一致
        String username = request.getParameter("username");
        String pwd = request.getParameter("password");
        if(!ROOT_NAME.equals(username) || !ROOT_PWD.equals(pwd)){
            throw new RuntimeException("账户或密码错误！");
        }

        user = new User();
        user.setUserName(username);
        user.setPassword(pwd);
        System.out.println(user.toString());
        return ContentValue.SUCCESS;
    }

    public User getUser() {
        return this.user;
    }

    public void setUser(User user) {
        this.user = user;
    }
}
